package com.yanqu.road.server.cmd.activity.feast.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ShanHeFeastProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SHAN_HE_FEAST_GET_RANK_REWARD_FROM_CROSS, desc = "领取榜单奖励  跨服返回")
public class FeastGetRankRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ShanHeFeastProto.CrossFeastGetRankRewardRespMsg respMsg = ShanHeFeastProto.CrossFeastGetRankRewardRespMsg.parseFrom(packet.getBytes());
        ret = player.getModule(ActivityModule.class).getFeastRankReward(
                respMsg.getActivityId(),
                respMsg.getConditionType(),
                respMsg.getRank()
        );
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShanHeFeastProto.FeastGetRankRewardRespMsg.Builder builder = ShanHeFeastProto.FeastGetRankRewardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SHAN_HE_FEAST_GET_RANK_REWARD, builder);
        }
    }
}
